using Godot;
using System;
//using GodotInk;
using System.Runtime.CompilerServices;
using System.Runtime;

public partial class FullScreenDialogView : WindowBase
{

	// Called when the node enters the scene tree for the first time.
	private TextureRect icon = null;
	private Label name = null;
	private RichTextLabel dialog = null;
	private AnimationPlayer anime = null;
	private Button skipButton = null;
	private string dialogText = "";

	//private InkStory story;
	public override void init()
	{
		base.init();

		this.icon = this.GetNode<TextureRect>("Camera2D/iconContainer/icon");
		this.name = this.GetNode<Label>("Camera2D/name");
		this.dialog = this.GetNode<RichTextLabel>("Camera2D/dialogContainer/dialog");
		this.anime = this.GetNode<AnimationPlayer>("dialogPlay");
		this.skipButton = this.GetNode<Button>("Camera2D/skipBtn");

		this.skipButton.Pressed += this.onClickSkipButton;

	}
	public override void onShow()
	{
		base.onShow();


		object inkObj;
		this.viewParamDict.TryGetValue("InkId", out inkObj);

		var inkId = (int)inkObj;

		this.LoadStory(inkId);
		//获取对话
		this.dialogText = "我觉得这里是测试我想写很多但是我打算赋值我觉得这里是测试我想写很多但是我打算赋值我觉得这里是测试我想写很多但是我打算赋值我觉得这里是测试我想写很多但是我打算赋值我觉得这里是测试我想写很多但是我打算赋值我觉得这里是测试我想写很多但是我打算赋值";
		this.dialog.Text = this.dialogText;
		this.anime.Play("playDialog");
		this.skipButton.Visible = true;
	}

	private void onClickSkipButton()
	{
		if (this.anime.IsPlaying())
		{
			this.anime.Stop();
		}

		this.dialog.VisibleRatio = 1;
		this.skipButton.Visible = false;
	}

	private void LoadStory(int intId)
	{
		/*var path = "";  //通过intId找到路径配置
		try
		{

			this.story = ResourceLoader.Load<InkStory>(path, null, ResourceLoader.CacheMode.Ignore);

		}
		catch (InvalidCastException)
		{
			GD.PrintErr($"{path} is not a valid ink story. "
					   + "Please make sure it was imported with `is_main_file` set to `true`.");
		}*/
	}
}
